package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-12-17 12:58
 **/
public class LeetCode1518 {

    //模拟
    /*public int numWaterBottles(int numBottles, int numExchange) {
        //把酒喝完后可以兑换的个数
        int sum = 0;
        while (numBottles >= numExchange) {
            sum += numExchange;
            numBottles = numBottles - numExchange + 1;
        }
        sum += numBottles;
        return sum;
    }*/

    //数学
    public int numWaterBottles(int numBottles, int numExchange) {
        return numBottles >= numExchange ? (numBottles - numExchange) / (numExchange - 1) + 1 + numBottles : numBottles;
    }

    public static void main(String[] args) {
        LeetCode1518 code = new LeetCode1518();
        System.out.println(code.numWaterBottles(9, 3));
    }
}
